/* Entry and CAP ExtJS XTemplates
* Updated: Feb 21, 2011
* Requires: ExtJS must already be loaded
* Copyright (c) 2011 MASAS Contributors.  Published under the
* Clear BSD License.  See license.txt for the full text of the license.
*/

// global
var Entry_Display_Template = new Ext.XTemplate(
  '<tpl for="entry">',
    '<div class="TemplateDisplayBox">',
      '<tpl if="typeof(id) != \'undefined\'">',
        '<h2>{id}</h2>',
      '</tpl>',
      '<tpl if="typeof(author) != \'undefined\'">',
        '<tpl for="author">',
          '<p><b>Author:</b> {name} &nbsp;&nbsp;&nbsp;',
          '<tpl if="typeof(uri) != \'undefined\'">',
            '<a href="{uri}" target="_blank">{uri}</a> </p>',
          '</tpl>',
        '</tpl>',
      '</tpl>',
      '<tpl if="typeof(published) != \'undefined\'">',
          '<p><b>Published:</b> {published} </p>',
      '</tpl>',
      '<tpl if="typeof(updated) != \'undefined\'">',
          '<p><b>Updated:</b> {updated} </p>',
      '</tpl>',
      '<tpl if="typeof(expires) != \'undefined\'">',
          '<p><b>Expires:</b> {[values.expires["#text"]]} </p>',
      '</tpl>',
    '</div>',
    '<tpl if="typeof(category) != \'undefined\'">',
      '<div class="TemplateDisplayBox">',
        '<h2>Categories</h2>',
        '<tpl for="category">',
          '<p><b>{[values["@label"]]}:</b> {[values["@term"]]} </p>',
        '</tpl>',
      '</div>',
    '</tpl>',
    '<tpl if="typeof(title) != \'undefined\'">',
      '<div class="TemplateDisplayBox">',
        '<h2>Title</h2>',
        '<tpl if="title[\'@type\'] == \'xhtml\'">',
          '<tpl for="title.div.div">',
//TODO: perhaps present the en/fr values as English/French??
            '<p><b>{[values["@xml:lang"]]}:</b> {[values["#text"]]} </p>',
          '</tpl>',
        '</tpl>',
        '<tpl if="title[\'@type\'] == \'text\'">',
// accessing the title object here using the root values
          '<p> {[values.title["#text"]]} </p>',
        '</tpl>',
      '</div>',
    '</tpl>',
    '<tpl if="typeof(content) != \'undefined\'">',
      '<div class="TemplateDisplayBox">',
        '<h2>Content</h2>',
        '<tpl if="content[\'@type\'] == \'xhtml\'">',
          '<tpl for="content.div.div">',
//TODO: perhaps present the en/fr values as English/French??
            '<p><b>{[values["@xml:lang"]]}:</b> {[values["#text"]]} </p>',
          '</tpl>',
        '</tpl>',
        '<tpl if="content[\'@type\'] == \'text\'">',
// accessing the content object here using the root values
          '<p> {[values.content["#text"]]} </p>',
        '</tpl>',
      '</div>',
    '</tpl>',
    '<tpl if="typeof(link) != \'undefined\'">',
      '<div class="TemplateDisplayBox">',
        '<h2>Related Links</h2>',
        '<tpl for="link">',
          '<tpl if="values[\'@rel\'] == \'related\'">',
            '<p> <a href="{[values[\'@href\']]}" target="_blank">{[values["@href"]]}</a> </p>',
          '</tpl>',
        '</tpl>',
      '</div>',
    '</tpl>',
  '</tpl>'
);

//Basic summary:
var CAP_Display_Template_Mini = new Ext.XTemplate(
  '<tpl for="alert">',
    '<div class="TemplateDisplayBox">',
      '<h2>{scope} {status} {msgType}</h2>',
	  '<p><b>Sender:</b> {sender} </p>',
      '<p><b>Identifier:</b> {identifier} </p>',
      '<p><b>Sent:</b> {sent} </p>',
	  '<p><b>Reference string:</b> {sender},{identifier},{sent}</p>',
    '</div>',
  '</tpl>');


//Basic summary:
var CAP_Display_Success = new Ext.XTemplate(
  '<tpl for="Success">',
    '<div class="TemplateDisplayBox">',
		'<tpl for="ParamList1">',
		'<h2>Success details for {value1}</h2>',
		'</tpl>',
		'<tpl for="ParamList2">',
		'<p><b>Channel Names:</b> {value1} </p>',
		'<p><b>Channel Status:</b> {value2} </p>',
		'<br/>',
		'<p><b>Errors?:</b> {value3} </p>',
		'<p><b>Status:</b> {value4} </p>',
		'</tpl>',
    '</div>',
  '</tpl>');

// global
var CAP_Display_Template = new Ext.XTemplate(
  '<tpl for="alert">',
    '<div class="TemplateDisplayBox">',
      '<h2>{scope} {status} {msgType}</h2>',
      '<p><b>Identifier:</b> {identifier} </p>',
      '<p><b>Sender:</b> {sender} </p>',
      '<p><b>Sent:</b> {sent} </p>',
    '</div>',
    '<tpl for="info">',
      '<div class="TemplateDisplayBox">',
        '<h2>{event}</h2>',
        '<tpl if="typeof(headline) != \'undefined\'">',
          '<p><b>Headline:</b> {headline} </p>',
        '</tpl>',
        '<tpl if="typeof(language) != \'undefined\'">',
          '<p><b>Language:</b>',
            '<tpl if="language == \'en-CA\'"> English </tpl>',
            '<tpl if="language == \'fr-CA\'"> French </tpl>',
            '<tpl if="language != \'en-CA\' && language != \'fr-CA\'"> {language} </tpl>',
          '</p>',
        '</tpl>',
        '<p><b>Urgency:</b> {urgency} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
          '<b>Severity:</b> {severity} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
          '<b>Certainty:</b> {certainty} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>',
        '<tpl if="typeof(expires) != \'undefined\'">',
          '<p><b>Expires:</b> {expires} </p>',
        '</tpl>',
        '<tpl if="typeof(senderName) != \'undefined\'">',
          '<p><b>Sender Name:</b> {senderName} </p>',
        '</tpl>',
        '<tpl if="typeof(contact) != \'undefined\'">',
          '<p><b>Contact:</b> {contact} </p>',
        '</tpl>',
        '<tpl if="typeof(web) != \'undefined\'">',
          '<p><b>Web:</b> <a href="{web}" target="_blank">{web}</a> </p>',
        '</tpl>',
        '<tpl if="typeof(description) != \'undefined\'">',
          '<p><b>Description:</b> {description} </p>',
        '</tpl>',
        '<tpl if="typeof(instruction) != \'undefined\'">',
          '<p><b>Instruction:</b> {instruction} </p>',
        '</tpl>',
        '<tpl if="typeof(area) != \'undefined\'">',
          '<p><b>Area:</b>',
          '<tpl for="area">',
            ' {areaDesc}, ',
          '</tpl>',
          '</p>',
        '</tpl>',
      '</div>',
    '</tpl>',
  '</tpl>'
);